import { CustomRoute, RoutePathKey } from '@/interface'
import { EnumRoutePath } from '@/enum'
import { Component } from 'vue'

export const RouteNameMap = new Map<RoutePathKey, RoutePathKey>(
  (Object.keys(EnumRoutePath) as RoutePathKey[]).map((v) => [v, v])
)

/**
 * 设置单个路由
 * @param route - 路由
 * @param notFoundName - 404未找到的路由名称
 * @param container - 路由容器
 */
export function setSingleRoute(container: Component, route: CustomRoute) {
  const routeItem: CustomRoute = {
    name: `${route.name as string}_`,
    path: `${route.path}_`,
    component: container,
    redirect: { name: RouteNameMap.get('not-found') },
    meta: {
      notMenu: true,
    },
    children: [route],
  }
  return routeItem
}
